|
7 | 7 | import com.easypost.http.Requestor;
|
8 | 8 | import com.easypost.http.Requestor.RequestMethod;
|
9 | 9 | import com.easypost.model.ShipmentCollection;
|
| 10 | +import com.easypost.model.EstimatedDeliveryDate; |
| 11 | +import com.easypost.model.EstimatedDeliveryDateResponse; |
10 | 12 | import com.easypost.model.Rate;
|
11 | 13 | import com.easypost.model.Shipment;
|
12 | 14 | import com.easypost.model.SmartRate;
|
@@ -85,8 +87,8 @@ public Shipment retrieve(final String id) throws EasyPostException {
|
85 | 87 | public ShipmentCollection all(final Map<String, Object> params) throws EasyPostException {
|
86 | 88 | String endpoint = "shipments";
|
87 | 89 |
|
88 |
| - ShipmentCollection shipmentCollection = |
89 |
| - Requestor.request(RequestMethod.GET, endpoint, params, ShipmentCollection.class, client); |
| 90 | + ShipmentCollection shipmentCollection = Requestor.request(RequestMethod.GET, endpoint, params, |
| 91 | + ShipmentCollection.class, client); |
90 | 92 | // we store the params in the collection so that we can use them to get the next page
|
91 | 93 | shipmentCollection.setPurchased(InternalUtilities.getOrDefault(params, "purchased", null));
|
92 | 94 | shipmentCollection.setIncludeChildren(InternalUtilities.getOrDefault(params, "include_children", null));
|
@@ -214,9 +216,8 @@ public List<SmartRate> smartrates(final String id) throws EasyPostException {
|
214 | 216 | public List<SmartRate> smartrates(final String id, final Map<String, Object> params) throws EasyPostException {
|
215 | 217 | String endpoint = "shipments/" + id + "/smartrate";
|
216 | 218 |
|
217 |
| - SmartrateCollection smartrateCollection = |
218 |
| - Requestor.request(RequestMethod.GET, endpoint, params, |
219 |
| - SmartrateCollection.class, client); |
| 219 | + SmartrateCollection smartrateCollection = Requestor.request(RequestMethod.GET, endpoint, params, |
| 220 | + SmartrateCollection.class, client); |
220 | 221 |
|
221 | 222 | return smartrateCollection.getSmartrates();
|
222 | 223 | }
|
@@ -322,7 +323,7 @@ public Shipment buy(final String id, final Map<String, Object> params, final boo
|
322 | 323 | * @throws EasyPostException when the request fails.
|
323 | 324 | */
|
324 | 325 | public Shipment buy(final String id, final Map<String, Object> params, final boolean withCarbonOffset,
|
325 |
| - final String endShipperId) throws EasyPostException { |
| 326 | + final String endShipperId) throws EasyPostException { |
326 | 327 | params.put("carbon_offset", withCarbonOffset);
|
327 | 328 |
|
328 | 329 | if (endShipperId != null && !endShipperId.isEmpty()) {
|
@@ -469,7 +470,7 @@ public SmartRate getLowestSmartRate(final List<SmartRate> smartRates, int delive
|
469 | 470 | * @throws EasyPostException when the request fails.
|
470 | 471 | */
|
471 | 472 | public SmartRate findLowestSmartrate(final List<SmartRate> smartRates, int deliveryDay,
|
472 |
| - SmartrateAccuracy deliveryAccuracy) throws EasyPostException { |
| 473 | + SmartrateAccuracy deliveryAccuracy) throws EasyPostException { |
473 | 474 | SmartRate lowestSmartrate = null;
|
474 | 475 |
|
475 | 476 | for (SmartRate rate : smartRates) {
|
@@ -524,4 +525,23 @@ public Shipment generateForm(final String id, final String formType, final Map<S
|
524 | 525 | return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, Shipment.class,
|
525 | 526 | client);
|
526 | 527 | }
|
| 528 | + |
| 529 | + /** |
| 530 | + * Retrieves the estimated delivery date of each Rate via SmartRate. |
| 531 | + * |
| 532 | + * @param id The id of the shipment. |
| 533 | + * @param plannedShipDate The planned shipment date. |
| 534 | + * @return EstimatedDeliveryDate object. |
| 535 | + * @throws EasyPostException |
| 536 | + */ |
| 537 | + public List<EstimatedDeliveryDate> retrieveEstimatedDeliveryDate(final String id, final String plannedShipDate) |
| 538 | + throws EasyPostException { |
| 539 | + HashMap<String, Object> params = new HashMap<>(); |
| 540 | + params.put("planned_ship_date", plannedShipDate); |
| 541 | + String endpoint = "shipments/" + id + "/smartrate/delivery_date"; |
| 542 | + |
| 543 | + EstimatedDeliveryDateResponse response = Requestor.request(RequestMethod.GET, endpoint, params, |
| 544 | + EstimatedDeliveryDateResponse.class, client); |
| 545 | + return response.getRates(); |
| 546 | + } |
527 | 547 | }
|
0 commit comments