Skip to content

Commit

Permalink
Added Look For new Destination based on provided Route IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
r4m-juan committed Mar 24, 2023
1 parent 644f3eb commit 008e6a9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.route4me</groupId>
<artifactId>route4me-java-sdk</artifactId>
<version>1.14.3</version>
<version>1.15.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> routeIDs = Arrays.asList("A42056A8120AF6EEDFAE3886B9909780", "724E95A9A4773F83B7236E8CA20E8F96");

try {
List<MatchedRoute> 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<Address> addresses = Arrays.asList(address);

routeManager.addAddressesToRoute(matchedRoute.getRouteID(), addresses);

} catch (APIException ex) {
Logger.getLogger(DynamicInsertStopOptimalAfterLastVisitedRouteIDs.class.getName()).log(Level.SEVERE, null, ex);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.google.gson.annotations.SerializedName;
import com.route4me.sdk.queryconverter.QueryParameter;
import java.util.List;
import lombok.Data;

/**
Expand Down Expand Up @@ -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<String> routeIDs;

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ private URIBuilder getURI(String endpoint) {

}

public List<MatchedRoute> lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit) throws APIException {
public List<MatchedRoute> lookForNewDestination(String scheduledFor, Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit, List<String> routeIDs) throws APIException {
URIBuilder builder = this.getURI(ROUTE_DYNAMIC_INSERT);

DynamicInsert body = new DynamicInsert();
body.setRouteInfoServer("v5");
body.setScheduledFor(scheduledFor);
Expand All @@ -63,9 +62,18 @@ public List<MatchedRoute> 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<ArrayList<MatchedRoute>>() {
}.getType());

}

public List<MatchedRoute> 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<MatchedRoute> lookForNewDestination(Double lat, Double lng, InsertMode insertMode, RecommendedBy recommendedBy, Integer limit, List<String> routeIDs) throws APIException {
return this.lookForNewDestination(null, lat, lng, insertMode, recommendedBy, limit, routeIDs);
}
}

0 comments on commit 008e6a9

Please sign in to comment.