package com.cargopooling.api.examples; import com.cargopooling.api.bean.authentication.TokenResult; import com.cargopooling.api.bean.smartcargo.JobResult; import com.cargopooling.api.bean.smartcargo.request.*; import com.cargopooling.api.bean.smartcargo.request.builder.*; import com.cargopooling.api.core.CargopoolingApiCore; import com.cargopooling.api.service.authentication.AccessTokenService; import com.cargopooling.api.service.smartcargo.ProblemResolverService; import java.io.IOException; /** * * * Copyright 2016 - Cargopoooling, Inc. - U.S.A. * Author: Cristian Costantini * www.cargopooling.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * **/ public class ProblemResolverExample { private final CargopoolingApiCore core; private final ProblemResolverService service; public ProblemResolverExample( String configPath ) throws IOException { this.core = new CargopoolingApiCore( configPath ); this.service = core.createProblemResolverService(); } public void resolve() throws Exception { // Get Access Token String token = connect(); ProblemBuilder.Builder problem = ProblemBuilder.newInstance(); // Add a new Vehicle Type problem.addVehicleType(VehicleTypeBuilder.newInstance("vehicle_type") .setCostPerDistance(1.0) .setCostPerTransportTime(1.0) .setCostPerServiceTime(1.0) .setCostPerDistance(1.0) .setFixedCost(1.0) .setMaxVelocity(40.0) .addCapacityDimension(0, 1) .build()); // Add a new Vehicle problem.addVehicle(VehicleBuilder.newInstance("vehicle_1", "vehicle_type") .addSkill("bananas") .setStartLocation(45.471668, 9.166214) .setReturnToDepot(true) .build()); // Add a new Service problem.addService((Service) ServiceBuilder.newInstance("Service_1") .addDimension(0, 1) .addSkill("bananas") .setLocation(45.466472, 9.159393) .setServiceTime(0.1) .build()); // Add a new Pickup problem.addPickup((Pickup) PickupBuilder.newInstance("Pickup_1") .addDimension(0, 1) .addSkill("bananas") .setLocation(45.466472, 9.159393) .setServiceTime(0.1) .build()); // Add a new Delivery problem.addDelivery((Delivery) DeliveryBuilder.newInstance("Delivery_1") .addDimension(0, 1) .addSkill("bananas") .setLocation(45.466472, 9.159393) .setServiceTime(0.1) .build()); // Add a new Shipment problem.addShipment((Shipment) ShipmentBuilder.newInstance("Shipment_1") .addDimension(0, 1) .addSkill("bananas") .setPickupLocation(45.466472, 9.159393) .setPickupServiceTime(0.1) .setDeliveryLocation(45.441196, 9.152020) .setDeliveryServiceTime(0.1) .build()); Problem request = problem.build(); JobResult result = (JobResult) service.resolve(token, request); } private String connect() throws Exception { AccessTokenService service = core.createAccessTokenService(); TokenResult tokenResult = service.getAccessToken(); return tokenResult.getResult(); } }
Problem Resolver Example
Have more questions? Submit a request
Comments