-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Examples of Orders with Demands, Optimization using callback UR…
…L and Advanced Constraints using Territories IDs
- Loading branch information
Showing
14 changed files
with
392 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/route4me/sdk/examples/SingleDriverRoundTripAsyncCallBackURL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// codebeat:disable[SIMILARITY] | ||
package com.route4me.sdk.examples; | ||
|
||
import com.route4me.sdk.exception.APIException; | ||
import com.route4me.sdk.services.routing.Constants.*; | ||
import com.route4me.sdk.services.routing.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SingleDriverRoundTripAsyncCallBackURL { | ||
|
||
public static void main(String[] args) { | ||
String apiKey = "11111111111111111111111111111111"; | ||
boolean disableRedirects = true; | ||
RoutingManager manager = new RoutingManager(apiKey, disableRedirects, "https://callback.url"); | ||
OptimizationParameters optParameters = new OptimizationParameters(); | ||
|
||
Parameters parameters = new Parameters(); | ||
parameters.setAlgorithmType(AlgorithmType.TSP.getValue()); | ||
parameters.setStoreRoute(Boolean.FALSE); | ||
parameters.setShareRoute(Boolean.FALSE); | ||
parameters.setRouteTime(0); | ||
parameters.setRouteMaxDuration(86400); | ||
parameters.setVehicleCapacity("1"); | ||
parameters.setVehicleMaxDistanceMi("10000"); | ||
parameters.setRouteName("Single Driver Round Trip"); | ||
parameters.setOptimize(Optimize.DISTANCE.toString()); | ||
parameters.setDistanceUnit(DistanceUnit.MI.toString()); | ||
parameters.setDeviceType(DeviceType.WEB.toString()); | ||
parameters.setTravelMode(TravelMode.DRIVING.toString()); | ||
optParameters.setParameters(parameters); | ||
|
||
List<Address> addresses = new ArrayList<>(); | ||
addresses.add(new Address("754 5th Ave New York, NY 10019", true, "Bergdorf Goodman", 40.7636197, -73.9744388, 0)); | ||
addresses.add(new Address("717 5th Ave New York, NY 10022", "Giorgio Armani", 40.7669692, -73.9693864, 0)); | ||
addresses.add(new Address("888 Madison Ave New York, NY 10014", "Ralph Lauren Women's and Home", 40.7715154, -73.9669241, 0)); | ||
addresses.add(new Address("1011 Madison Ave New York, NY 10075", "Yigal Azrou'l", 40.7772129, -73.9669, 0)); | ||
addresses.add(new Address("440 Columbus Ave New York, NY 10024", "Frank Stella Clothier", 40.7808364, -73.9732729, 0)); | ||
addresses.add(new Address("324 Columbus Ave #1 New York, NY 10023", "Liana", 40.7803123, -73.9793079, 0)); | ||
addresses.add(new Address("110 W End Ave New York, NY 10023", "Toga Bike Shop", 40.7753077, -73.9861529, 0)); | ||
addresses.add(new Address("555 W 57th St New York, NY 10019", "BMW of Manhattan", 40.7718005, -73.9897716, 0)); | ||
addresses.add(new Address("57 W 57th St New York, NY 10019", "Verizon Wireless", 40.7558695, -73.9862019, 0)); | ||
optParameters.setAddresses(addresses); | ||
|
||
try { | ||
DataObject responseObject = manager.runOptimization(optParameters); | ||
System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId()); | ||
System.out.println("State:" + OptimizationState.get(responseObject.getState().intValue())); | ||
if (responseObject.getAddresses() != null) { | ||
for (Address address : responseObject.getAddresses()) { | ||
System.out.println(address); | ||
} | ||
} | ||
} catch (APIException e) { | ||
//handle exception | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
// codebeat:enable[SIMILARITY] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
...main/java/com/route4me/sdk/examples/advancedconstraints/AdvancedConstraintsExample13.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.route4me.sdk.examples.advancedconstraints; | ||
|
||
import com.route4me.sdk.exception.APIException; | ||
import com.route4me.sdk.services.routing.Address; | ||
import com.route4me.sdk.services.routing.Constants.AlgorithmType; | ||
import com.route4me.sdk.services.routing.Constants.DeviceType; | ||
import com.route4me.sdk.services.routing.Constants.OptimizationState; | ||
import com.route4me.sdk.services.routing.Constants.TravelMode; | ||
import com.route4me.sdk.services.routing.DataObject; | ||
import com.route4me.sdk.services.routing.OptimizationParameters; | ||
import com.route4me.sdk.services.routing.Parameters; | ||
import com.route4me.sdk.services.routing.RoutingManager; | ||
import com.route4me.sdk.services.routing.advancedconstraints.AdvancedConstraints; | ||
import com.route4me.sdk.services.territories.TerritoriesManager; | ||
import com.route4me.sdk.services.territories.Territory; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* | ||
* @author juan | ||
*/ | ||
public class AdvancedConstraintsExample13 { | ||
|
||
|
||
|
||
public static void main(String[] args) { | ||
try { | ||
String apiKey = "11111111111111111111111111111111"; | ||
RoutingManager manager = new RoutingManager(apiKey, true); | ||
OptimizationParameters optParameters = new OptimizationParameters(); | ||
|
||
//********************************************************************** | ||
// TEST CASE: Optimization using Territories addresses | ||
// 3 Territories | ||
//********************************************************************** | ||
|
||
TerritoriesManager territoriesManager = new TerritoriesManager(apiKey); | ||
|
||
|
||
Parameters parameters = new Parameters(); | ||
parameters.setAlgorithmType(AlgorithmType.ADVANCED_CVRP_TW.getValue()); | ||
parameters.setStoreRoute(Boolean.FALSE); | ||
parameters.setShareRoute(Boolean.FALSE); | ||
parameters.setRouteTime((8 + 5) * 3600); | ||
parameters.setRouteName("Single Depot, Multiple Driver - 3 Territories IDs"); | ||
parameters.setDeviceType(DeviceType.WEB.toString()); | ||
parameters.setTravelMode(TravelMode.DRIVING.toString()); | ||
optParameters.setParameters(parameters); | ||
|
||
// Depot | ||
Address depot = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", 38.141598, -85.793846); | ||
List<Object> depots = Arrays.asList(depot); | ||
parameters.setDepots(depots); | ||
|
||
|
||
// Territories | ||
// ********************** | ||
List<String> zone1 = Arrays.asList("584BE87F75599DD8B9F038D81A33F5A8"); | ||
List<String> zone2 = Arrays.asList("A5C1B85BCC069FF6CBDA18A65DC95031"); | ||
List<String> zone3 = Arrays.asList("007AE22B494A149B52A45E3C6D3EC0CA"); | ||
|
||
|
||
|
||
List<Address> addresses = new ArrayList<>(); | ||
|
||
Address address; | ||
|
||
Territory territory = territoriesManager.getAddressesInTerritory(zone1.get(0)); | ||
for (Integer contactId: territory.getAddresses()){ | ||
address = new Address(); | ||
address.setContactId(contactId); | ||
address.setTags(zone1); | ||
addresses.add(address); | ||
} | ||
|
||
territory = territoriesManager.getAddressesInTerritory(zone2.get(0)); | ||
for (Integer contactId: territory.getAddresses()){ | ||
address = new Address(); | ||
address.setContactId(contactId); | ||
address.setTags(zone2); | ||
addresses.add(address); | ||
} | ||
|
||
territory = territoriesManager.getAddressesInTerritory(zone3.get(0)); | ||
for (Integer contactId: territory.getAddresses()){ | ||
address = new Address(); | ||
address.setTags(zone3); | ||
address.setContactId(contactId); | ||
addresses.add(address); | ||
} | ||
|
||
AdvancedConstraints schedule1 = new AdvancedConstraints(); | ||
schedule1.setTags(zone1); | ||
schedule1.setMembersCount(3); | ||
List<List<Integer>> timeWindowsSchedule1 = new ArrayList<>(); | ||
List<Integer> timeWindowSchedule1 = Arrays.asList((8 + 5) * 3600 , (11 + 5) * 3600); | ||
timeWindowsSchedule1.add(timeWindowSchedule1); | ||
schedule1.setAvailableTimeWindows(timeWindowsSchedule1); | ||
|
||
|
||
// Schedule 2 | ||
// Time Window Start: 8:00 am EST | ||
// Time Window End: 12:00 pm EST | ||
AdvancedConstraints schedule2 = new AdvancedConstraints(); | ||
schedule2.setTags(zone2); | ||
schedule2.setMembersCount(4); | ||
List<List<Integer>> timeWindowsSchedule2 = new ArrayList<>(); | ||
List<Integer> timeWindowSchedule2 = Arrays.asList((8 + 5) * 3600 , (12 + 5) * 3600); | ||
timeWindowsSchedule2.add(timeWindowSchedule2); | ||
schedule2.setAvailableTimeWindows(timeWindowsSchedule2); | ||
|
||
|
||
// Schedule 3 | ||
// Time Window Start: 8:00 am EST | ||
// Time Window End: 01:00 pm EST | ||
AdvancedConstraints schedule3 = new AdvancedConstraints(); | ||
schedule3.setTags(zone3); | ||
schedule3.setMembersCount(3); | ||
List<List<Integer>> timeWindowsSchedule3 = new ArrayList<>(); | ||
List<Integer> timeWindowSchedule3 = Arrays.asList((8 + 5) * 3600 , (13 + 5) * 3600); | ||
timeWindowsSchedule3.add(timeWindowSchedule3); | ||
schedule3.setAvailableTimeWindows(timeWindowsSchedule3); | ||
|
||
|
||
// Schedules registration | ||
List<AdvancedConstraints> advancedConstraints = Arrays.asList(schedule1, schedule2, schedule3); | ||
parameters.setAdvancedConstraints(advancedConstraints); | ||
|
||
optParameters.setAddresses(addresses); | ||
|
||
try { | ||
DataObject responseObject = manager.runOptimization(optParameters); | ||
System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId()); | ||
System.out.println("State:" + OptimizationState.get(responseObject.getState().intValue())); | ||
if (responseObject.getAddresses() != null) { | ||
for (Address addressResponse : responseObject.getAddresses()) { | ||
System.out.println(addressResponse); | ||
} | ||
} | ||
} catch (APIException e) { | ||
//handle exception | ||
e.printStackTrace(); | ||
} | ||
} catch (APIException ex) { | ||
Logger.getLogger(AdvancedConstraintsExample13.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.