Skip to content

Commit

Permalink
Add smartrate endpoints functions (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 authored Jul 15, 2024
1 parent b3edb2f commit 98dafa5
Show file tree
Hide file tree
Showing 20 changed files with 645 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next Release

- Adds new `shipment.recommendShipDate`, `smartrate.recommendShipDate`, and `smartrate.estimateDeliveryDate` functions
- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint
- Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update?utm_medium=email&_hsenc=p2ANqtz-96MmFtWICOzy9sKRbbcZSiMovZSrY3MSX1_bgY9N3f9yLVfWQdLhjAGq-SmNcOnDIS6GYhZ0OApjDBrGkKyLLMx1z6_TFOVp6-wllhEFQINrkuRuc&_hsmi=313130292&utm_content=313130292&utm_source=hs_email) for more details

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.easypost.model;

import lombok.Getter;

@Getter
public class DeliveryDateForZipPairEstimate {
private String carrier;
private String service;
private TimeInTransitDetailsForDeliveryDate easypostTimeInTransitData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.easypost.model;

import java.util.List;
import lombok.Getter;

@Getter
public class EstimateDeliveryDateForZipPairResult {
private Boolean saturdayDelivery;
private List<DeliveryDateForZipPairEstimate> results;
private List<String> carriersWithoutTintEstimates;
private String desiredDeliveryDate;
private String fromZip;
private String toZip;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.easypost.model;

import lombok.Getter;

@Getter
public class RecommendShipDateForShipmentResult {
private TimeInTransitDetailsForShipDateRecommendation easypostTimeInTransitData;
private Rate rate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.easypost.model;

import java.util.List;

import lombok.Getter;

@Getter
public class RecommendShipDateForZipPairResult {
private Boolean saturdayDelivery;
private List<ShipDateForZipPairRecommendation> results;
private List<String> carriersWithoutTintEstimates;
private String desiredDeliveryDate;
private String fromZip;
private String toZip;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.easypost.model;

import java.util.List;
import lombok.Getter;

@Getter
public class RecommendShipDateResponse {
private List<RecommendShipDateForShipmentResult> rates;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.easypost.model;

import lombok.Getter;

@Getter
public class ShipDateForZipPairRecommendation {
private String carrier;
private String service;
private TimeInTransitDetailsForShipDate easypostTimeInTransitData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.easypost.model;

import java.util.Date;
import lombok.Getter;

@Getter
public class TimeInTransitDetailsForDeliveryDate {
private Date easypostEstimatedDeliveryDate;
private TimeInTransit daysInTransit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.easypost.model;

import java.util.Date;
import lombok.Getter;

@Getter
public class TimeInTransitDetailsForShipDate {
private Date shipOnDate;
private Float deliveryDateConfidence;
private int estimatedTransitDays;
private TimeInTransit daysInTransit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.easypost.model;

import java.util.Date;
import lombok.Getter;

@Getter
public class TimeInTransitDetailsForShipDateRecommendation {
private Date desiredDeliveryDate;
private Float deliveryDateConfidence;
private String estimatedTransitDays;
private String shipOnDate;
private TimeInTransit daysInTransit;
}
2 changes: 2 additions & 0 deletions src/main/java/com/easypost/service/EasyPostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class EasyPostClient {
public final ReportService report;
public final ScanformService scanForm;
public final ShipmentService shipment;
public final SmartRateService smartRate;
public final TrackerService tracker;
public final UserService user;
public final WebhookService webhook;
Expand Down Expand Up @@ -150,6 +151,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
this.report = new ReportService(this);
this.scanForm = new ScanformService(this);
this.shipment = new ShipmentService(this);
this.smartRate = new SmartRateService(this);
this.tracker = new TrackerService(this);
this.user = new UserService(this);
this.webhook = new WebhookService(this);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/easypost/service/ShipmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.easypost.model.EstimatedDeliveryDate;
import com.easypost.model.EstimatedDeliveryDateResponse;
import com.easypost.model.Rate;
import com.easypost.model.RecommendShipDateForShipmentResult;
import com.easypost.model.RecommendShipDateResponse;
import com.easypost.model.Shipment;
import com.easypost.model.SmartRate;
import com.easypost.model.SmartrateAccuracy;
Expand Down Expand Up @@ -461,4 +463,24 @@ public List<EstimatedDeliveryDate> retrieveEstimatedDeliveryDate(final String id
EstimatedDeliveryDateResponse.class, client);
return response.getRates();
}

/**
* Retrieve a recommended ship date for an existing Shipment via the Precision Shipping API,
* based on a specific desired delivery date.
*
* @param id The id of the shipment.
* @param desiredDeliveryDate The desired delivery date.
* @return EstimatedDeliveryDate object.
* @throws EasyPostException When the request fails.
*/
public List<RecommendShipDateForShipmentResult> recommendShipDate(final String id, final String desiredDeliveryDate)
throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
params.put("desired_delivery_date", desiredDeliveryDate);
String endpoint = "shipments/" + id + "/smartrate/precision_shipping";

RecommendShipDateResponse response = Requestor.request(RequestMethod.GET, endpoint, params,
RecommendShipDateResponse.class, client);
return response.getRates();
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/easypost/service/SmartRateService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.easypost.service;

import java.util.Map;

import com.easypost.exception.EasyPostException;
import com.easypost.http.Requestor;
import com.easypost.http.Requestor.RequestMethod;
import com.easypost.model.EstimateDeliveryDateForZipPairResult;
import com.easypost.model.RecommendShipDateForZipPairResult;

public class SmartRateService {
private final EasyPostClient client;

/**
* TrackerService constructor.
*
* @param client The client object.
*/
SmartRateService(EasyPostClient client) {
this.client = client;
}

/**
* Retrieve a recommended ship date for an existing Shipment via the Precision Shipping API,
* based on a specific desired delivery date.
*
* @param params Parameters to include on the API call.
* @return EstimatedDeliveryDate object.
* @throws EasyPostException When the request fails.
*/
public RecommendShipDateForZipPairResult recommendShipDate(final Map<String, Object> params)
throws EasyPostException {
String endpoint = "smartrate/deliver_on";

return Requestor.request(RequestMethod.POST, endpoint, params, RecommendShipDateForZipPairResult.class, client);
}

/**
* Retrieve the estimated delivery date of each carrier-service level combination via the
* Smart Deliver By API, based on a specific ship date and origin-destination postal code pair.
*
* @param params Parameters to include on the API call.
* @return EstimatedDeliveryDate object.
* @throws EasyPostException When the request fails.
*/
public EstimateDeliveryDateForZipPairResult estimateDeliveryDate(final Map<String, Object> params)
throws EasyPostException {
String endpoint = "smartrate/deliver_by";

return Requestor.request(RequestMethod.POST, endpoint, params,
EstimateDeliveryDateForZipPairResult.class, client);
}
}
Loading

0 comments on commit 98dafa5

Please sign in to comment.