Skip to content

Commit 008e6a9

Browse files
committed
Added Look For new Destination based on provided Route IDs
1 parent 644f3eb commit 008e6a9

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.route4me</groupId>
66
<artifactId>route4me-java-sdk</artifactId>
7-
<version>1.14.3</version>
7+
<version>1.15.0</version>
88
<packaging>jar</packaging>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2022 Route4Me.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package com.route4me.sdk.examples.routes.dynamic.insert;
25+
26+
import com.route4me.sdk.exception.APIException;
27+
import com.route4me.sdk.services.routing.Address;
28+
import com.route4me.sdk.services.routing.RoutingManager;
29+
import com.route4me.sdk.services.routing.dynamic.insert.DynamicInsertManager;
30+
import com.route4me.sdk.services.routing.dynamic.insert.InsertMode;
31+
import com.route4me.sdk.services.routing.dynamic.insert.MatchedRoute;
32+
import com.route4me.sdk.services.routing.dynamic.insert.RecommendedBy;
33+
import java.util.Arrays;
34+
import java.util.List;
35+
import java.util.logging.Level;
36+
import java.util.logging.Logger;
37+
38+
/**
39+
*
40+
* @author route4me
41+
*/
42+
public class DynamicInsertStopOptimalAfterLastVisitedRouteIDs {
43+
44+
public static void main(String[] args) {
45+
String apiKey = System.getenv("R4M_API_KEY");
46+
47+
DynamicInsertManager dynamicManager = new DynamicInsertManager(apiKey);
48+
RoutingManager routeManager = new RoutingManager(apiKey);
49+
50+
Address address = new Address("Address 1", 43.103865, -79.093727);
51+
List<String> routeIDs = Arrays.asList("A42056A8120AF6EEDFAE3886B9909780", "724E95A9A4773F83B7236E8CA20E8F96");
52+
53+
try {
54+
List<MatchedRoute> matchedRoutes = dynamicManager.lookForNewDestination(address.getLatitude(), address.getLongitude(), InsertMode.OPTIMAL_AFTER_LAST_VISITED, RecommendedBy.DISTANCE, 5, routeIDs);
55+
for (MatchedRoute matchedRoute : matchedRoutes) {
56+
System.out.println(matchedRoute);
57+
}
58+
System.out.println("Inserting Stop into first Route from the List");
59+
60+
MatchedRoute matchedRoute = matchedRoutes.get(0);
61+
address.setSequenceNo(matchedRoute.getRecommendedInsertionStopNumber());
62+
63+
List<Address> addresses = Arrays.asList(address);
64+
65+
routeManager.addAddressesToRoute(matchedRoute.getRouteID(), addresses);
66+
67+
} catch (APIException ex) {
68+
Logger.getLogger(DynamicInsertStopOptimalAfterLastVisitedRouteIDs.class.getName()).log(Level.SEVERE, null, ex);
69+
}
70+
71+
}
72+
73+
}

src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsert.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.google.gson.annotations.SerializedName;
2727
import com.route4me.sdk.queryconverter.QueryParameter;
28+
import java.util.List;
2829
import lombok.Data;
2930

3031
/**
@@ -58,5 +59,8 @@ public class DynamicInsert {
5859
@SerializedName("max_increase_percent_allowed")
5960
@QueryParameter("max_increase_percent_allowed")
6061
private Integer maxIncreasePercentAllowed;
62+
@SerializedName("route_ids")
63+
@QueryParameter("route_ids")
64+
private List<String> routeIDs;
6165

6266
}

src/main/java/com/route4me/sdk/services/routing/dynamic/insert/DynamicInsertManager.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ private URIBuilder getURI(String endpoint) {
5252

5353
}
5454

55-
public List<MatchedRoute> lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit) throws APIException {
55+
public List<MatchedRoute> lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit, List<String> routeIDs) throws APIException {
5656
URIBuilder builder = this.getURI(ROUTE_DYNAMIC_INSERT);
57-
5857
DynamicInsert body = new DynamicInsert();
5958
body.setRouteInfoServer("v5");
6059
body.setScheduledFor(scheduledFor);
@@ -63,9 +62,18 @@ public List<MatchedRoute> lookForNewDestination(String scheduledFor, Double lat,
6362
body.setInsertMode(insertMode.getValue());
6463
body.setLookupResultsLimit(limit);
6564
body.setRecommendBy(recommendedBy.getValue());
65+
body.setRouteIDs(routeIDs);
6666

6767
return this.makeJSONRequest(RequestMethod.POST, builder, body, new TypeToken<ArrayList<MatchedRoute>>() {
6868
}.getType());
6969

7070
}
71+
72+
public List<MatchedRoute> lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit) throws APIException {
73+
return this.lookForNewDestination(scheduledFor, lat, lng, insertMode, recommendedBy, limit, null);
74+
}
75+
76+
public List<MatchedRoute> lookForNewDestination(Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit, List<String> routeIDs) throws APIException {
77+
return this.lookForNewDestination(null, lat, lng, insertMode, recommendedBy, limit, routeIDs);
78+
}
7179
}

0 commit comments

Comments
 (0)