Skip to content

Commit

Permalink
Add smartrate endpoints functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 committed Jul 12, 2024
1 parent b3edb2f commit 0ebf1fd
Show file tree
Hide file tree
Showing 16 changed files with 601 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,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,10 @@
package com.easypost.model;

import lombok.Getter;

@Getter
public class ShipDateForZipPairRecommendation {
private String carrier;
private String service;
private TimeInTransitDetailsForDeliveryDate easypostTimeInTransitData;
}
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 TimeInTransitDetailsForDeliveryDate {
private Date shipOnDate;
private Float deliveryDateConfidence;
private int estimatedTransitDays;
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
20 changes: 20 additions & 0 deletions src/main/java/com/easypost/service/ShipmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,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<EstimatedDeliveryDate> 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";

EstimatedDeliveryDateResponse response = Requestor.request(RequestMethod.GET, endpoint, params,
EstimatedDeliveryDateResponse.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);
}
}
180 changes: 180 additions & 0 deletions src/test/cassettes/shipment/retrieve_recommend_date.json

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions src/test/cassettes/smart_rate/retrieve_recommend_ship_date.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/test/java/com/easypost/CarrierAccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testCreateWithCustomWorkflow() throws EasyPostException {


/**
* Test creating a carrier account with a custom workflow.
* Test creating a UPS carrier account.
*
* @throws EasyPostException when the request fails.
*/
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/com/easypost/Fixtures.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ public static HashMap<String, Object> referralUser() {
* @return The default planned ship date
*/
public static String plannedShipDate() {
return "2023-12-28";
return "2024-07-16";
}

/**
* Get the default desired delivery date.
*
* @return The default desired delivery date
*/
public static String desiredDeliveryDate() {
return "2024-07-16";
}
}
Loading

0 comments on commit 0ebf1fd

Please sign in to comment.