From 008e6a9e0c59899a8a3c7102d3cf9e46ba27552c Mon Sep 17 00:00:00 2001 From: juanroute4me Date: Fri, 24 Mar 2023 12:36:06 -0500 Subject: [PATCH] Added Look For new Destination based on provided Route IDs --- pom.xml | 2 +- ...rtStopOptimalAfterLastVisitedRouteIDs.java | 73 +++++++++++++++++++ .../routing/dynamic/insert/DynamicInsert.java | 4 + .../dynamic/insert/DynamicInsertManager.java | 12 ++- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/route4me/sdk/examples/routes/dynamic/insert/DynamicInsertStopOptimalAfterLastVisitedRouteIDs.java diff --git a/pom.xml b/pom.xml index d879276..af62b0a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.route4me route4me-java-sdk - 1.14.3 + 1.15.0 jar UTF-8 diff --git a/src/main/java/com/route4me/sdk/examples/routes/dynamic/insert/DynamicInsertStopOptimalAfterLastVisitedRouteIDs.java b/src/main/java/com/route4me/sdk/examples/routes/dynamic/insert/DynamicInsertStopOptimalAfterLastVisitedRouteIDs.java new file mode 100644 index 0000000..6a7c336 --- /dev/null +++ b/src/main/java/com/route4me/sdk/examples/routes/dynamic/insert/DynamicInsertStopOptimalAfterLastVisitedRouteIDs.java @@ -0,0 +1,73 @@ +/* + * The MIT License + * + * Copyright 2022 Route4Me. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.route4me.sdk.examples.routes.dynamic.insert; + +import com.route4me.sdk.exception.APIException; +import com.route4me.sdk.services.routing.Address; +import com.route4me.sdk.services.routing.RoutingManager; +import com.route4me.sdk.services.routing.dynamic.insert.DynamicInsertManager; +import com.route4me.sdk.services.routing.dynamic.insert.InsertMode; +import com.route4me.sdk.services.routing.dynamic.insert.MatchedRoute; +import com.route4me.sdk.services.routing.dynamic.insert.RecommendedBy; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author route4me + */ +public class DynamicInsertStopOptimalAfterLastVisitedRouteIDs { + + public static void main(String[] args) { + String apiKey = System.getenv("R4M_API_KEY"); + + DynamicInsertManager dynamicManager = new DynamicInsertManager(apiKey); + RoutingManager routeManager = new RoutingManager(apiKey); + + Address address = new Address("Address 1", 43.103865, -79.093727); + List routeIDs = Arrays.asList("A42056A8120AF6EEDFAE3886B9909780", "724E95A9A4773F83B7236E8CA20E8F96"); + + try { + List matchedRoutes = dynamicManager.lookForNewDestination(address.getLatitude(), address.getLongitude(), InsertMode.OPTIMAL_AFTER_LAST_VISITED, RecommendedBy.DISTANCE, 5, routeIDs); + for (MatchedRoute matchedRoute : matchedRoutes) { + System.out.println(matchedRoute); + } + System.out.println("Inserting Stop into first Route from the List"); + + MatchedRoute matchedRoute = matchedRoutes.get(0); + address.setSequenceNo(matchedRoute.getRecommendedInsertionStopNumber()); + + List
addresses = Arrays.asList(address); + + routeManager.addAddressesToRoute(matchedRoute.getRouteID(), addresses); + + } catch (APIException ex) { + Logger.getLogger(DynamicInsertStopOptimalAfterLastVisitedRouteIDs.class.getName()).log(Level.SEVERE, null, ex); + } + + } + +} diff --git a/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsert.java b/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsert.java index 94c174f..7574793 100644 --- a/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsert.java +++ b/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsert.java @@ -25,6 +25,7 @@ import com.google.gson.annotations.SerializedName; import com.route4me.sdk.queryconverter.QueryParameter; +import java.util.List; import lombok.Data; /** @@ -58,5 +59,8 @@ public class DynamicInsert { @SerializedName("max_increase_percent_allowed") @QueryParameter("max_increase_percent_allowed") private Integer maxIncreasePercentAllowed; + @SerializedName("route_ids") + @QueryParameter("route_ids") + private List routeIDs; } diff --git a/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsertManager.java b/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsertManager.java index ecf2470..9fcf38d 100644 --- a/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsertManager.java +++ b/src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsertManager.java @@ -52,9 +52,8 @@ private URIBuilder getURI(String endpoint) { } - public List lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit) throws APIException { + public List lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit, List routeIDs) throws APIException { URIBuilder builder = this.getURI(ROUTE_DYNAMIC_INSERT); - DynamicInsert body = new DynamicInsert(); body.setRouteInfoServer("v5"); body.setScheduledFor(scheduledFor); @@ -63,9 +62,18 @@ public List lookForNewDestination(String scheduledFor, Double lat, body.setInsertMode(insertMode.getValue()); body.setLookupResultsLimit(limit); body.setRecommendBy(recommendedBy.getValue()); + body.setRouteIDs(routeIDs); return this.makeJSONRequest(RequestMethod.POST, builder, body, new TypeToken>() { }.getType()); } + + public List lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit) throws APIException { + return this.lookForNewDestination(scheduledFor, lat, lng, insertMode, recommendedBy, limit, null); + } + + public List lookForNewDestination(Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit, List routeIDs) throws APIException { + return this.lookForNewDestination(null, lat, lng, insertMode, recommendedBy, limit, routeIDs); + } }