With effect from 02 January 2021, we will deprecate support for this client library and there will be no future updates. If you are currently using the client library, the integrations done based on it should still be able to work. Moving forward, we recommend the use of our API documentation (Dashboard and Routing Engine) to build your integration.
You have a fleet of just 10 vehicles to serve 500 spots in the city. Some vehicles are only available in the day. Some stops can only be served at night. How would you solve this problem?
You don't need to. Just throw us an array of stops, vehicles and depots and we will do the heavy lifting for you. Routing as a Service!
IMPORTANT NOTE: This will only run on Java 11 and above! If you have lower versions of Java, you need to install JDK 11!
ElasticRoute offers two APIs depending on your needs, and different sections of this documentation are relevant to you depending on which API you wish to interact with:
- Routing Engine API – if you already have your own fleet management system and you only wish to use ElasticRoute to solve the routing problem and inspect the solution. This is effectively using ElasticRoute in a headless environment, a.k.a. "routing as a service".
- Dashboard API – if your team uses the ElasticRoute web application to review stops and vehicles on a map, and you wish to push data from your existing applications to the ElasticRoute dashboard. Regardless of how you use ElasticRoute, this client library is capable of interacting with both services.
<dependencies>
<dependency>
<groupId>com.detrack.elasticroute</groupId>
<artifactId>routingengine</artifactId>
<version>1.3</version>
</dependency>
</dependencies>Note: For IntelliJ IDE, because the default target bytecode is 1.5 which is incompatible with this library, you should add the following to your pom.xml. This is to ensure it is using javac 11.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>To create a plan, you need to create List<Stop>, List<Depot>, List<Vehicle, and generalSettings
For the full list of generalSettings please refer to this link
// creating a list of stops
List<Stop> stops = new ArrayList<>();
Stop stop1 = new Stop("stop1", "address1");
Stop stop2 = new Stop("stop2", "address2");
Stop stop3 = new Stop("stop3", "address3");
stops.add(stop1);
stops.add(stop2);
stops.add(stop3);
// creating a list of vehicles
Vehicle vehicle1 = new Vehicle("name1");
Vehicle vehicle2 = new Vehicle("name2");
Vehicle vehicle3 = new Vehicle("name3");
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(vehicle1);
vehicles.add(vehicle2);
vehicles.add(vehicle3);
// creating a list of depots
Depot depot1 = new Depot("name1", "address1");
Depot depot2 = new Depot("name3", "address3");
Depot depot3 = new Depot("name2", "address2");
List<Depot> depots = new ArrayList<>();
depots.add(depot1);
depots.add(depot2);
depots.add(depot3);
// creating the general settings
GeneralSettings generalSettings = new GeneralSettings("SG", "Asia/Singapore");
// Instantiate the Plan
Plan plan = new Plan(stops, depots, vehicles, generalSettings);
Note: id is the unique identifier for your plan. You can retrieve your plan using this id.
// Instantiate a plan before this code. In this example the name of the instantiated plan is plan
Plan.createPlan(plan, "id")Plan.getPlan("id");Returns a String
Plan.getPlanStatus("id");Stops an ongoing plan
Plan.stopPlan("id");Deletes the plan with the specified id
Plan.deletePlan("id");<dependencies>
<dependency>
<groupId>com.detrack.elasticroute</groupId>
<artifactId>dashboard</artifactId>
<version>1.3</version>
</dependency>
</dependencies>Note: For IntelliJ IDE, because the default target bytecode is 1.5 which is incompatible with this library, you should add the following to your pom.xml. This is to ensure it is using javac 11.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>Note : List of fields is specified in the online API documentation
Note: Date format is YYYY-MM-DD
Stop stop = new Stop("stopName", "address");Stop.getStop("stopName", "date");Stop stop = new Stop("stopName", "address");
Stop.createStop(stop, "date");Stop stop = new Stop("stopName", "address");
// (optional) Change the fields here
Stop.setDepot("Warehouse1");
stop.updateStop();Stop stop = new Stop("stopName", "address");
stop.updateStop("stopToUpdate", "date");Stop.deleteStop("stopName", "date");Note : List of fields is specified in the online API documentation
List<Stop> stops = Stop.getStops("date");or
List<Stop> stops = Stop.getStops("date", int limit, int pageNumber);List<Stop> stops = new ArrayList<>();
Stop stop1 = new Stop("stop1", "address1");
Stop stop2 = new Stop("stop2", "address2");
Stop stop3 = new Stop("stop3", "address3");
stops.add(stop1);
stops.add(stop2);
stops.add(stop3);
Stop.createStops(stops, "date");Note: This will delete ALL the stops on the specified date and replace it with the new one.
List<Stop> stops = new ArrayList<>();
Stop stop1 = new Stop("stop1", "address1");
Stop stop2 = new Stop("stop2", "address2");
Stop stop3 = new Stop("stop3", "address3");
stops.add(stop1);
stops.add(stop2);
stops.add(stop3);
Stop.replaceAllStops(stops, "date");Stop.deleteStops("date");Note : List of fields is specified in the online API documentation
Vehicle vehicle = new Vehicle("name");Vehicle vehicle = Vehicle.getVehicle("name");Vehicle vehicle = new Vehicle("name");
Vehicle.createVehicle(vehicle);Vehicle vehicle = new Vehicle("newName");
// (optional) Change the fields here
vehicle.setAvailMon(false);
vehicle.updateVehicle();Vehicle vehicle = new Vehicle("newName");
// (optional) Change the fields here
vehicle.setAvailMon(false);
vehicle.updateVehicle("nameOfVehicleToUpdate");Vehicle.deleteVehicle("name");List<Vehicle> vehicles = Vehicle.getVehicles();or
List<Vehicle> vehicles = Vehicle.getVehicles(int limit, int pageNumber);Vehicle vehicle1 = new Vehicle("name1");
Vehicle vehicle2 = new Vehicle("name2");
Vehicle vehicle3 = new Vehicle("name3");
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(vehicle1);
vehicles.add(vehicle2);
vehicles.add(vehicle3);
Vehicle.createVehicles(vehicles);Vehicle vehicle1 = new Vehicle("name1");
Vehicle vehicle2 = new Vehicle("name2");
Vehicle vehicle3 = new Vehicle("name3");
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(vehicle1);
vehicles.add(vehicle2);
vehicles.add(vehicle3);
Vehicle.replaceAllVehicles(vehicles);Vehicle vehicle1 = new Vehicle("name1");
Vehicle vehicle2 = new Vehicle("name2");
Vehicle vehicle3 = new Vehicle("name3");
// (optional) Change the fields here
vehicle1.setAvail(false);
vehicle2.setPriority(10);
List<Vehicle> vehicles = new ArrayList<>();
vehicles.add(vehicle1);
vehicles.add(vehicle2);
vehicles.add(vehicle3);
Vehicle.updateVehicles(vehicles);Note: This will delete ALL your vehicles
Vehicle.deleteVehicles();Note: Date format is YYYY-MM-DD
Plan.startPlan("date");This will stop an ongoing plan
Plan.stopPlan("date");String status = Plan.getPlanStatus("date");Acknowledgement : This library is made using EA-Async library