|
| 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 | +} |
0 commit comments