33import com .easypost .exception .EasyPostException ;
44import com .easypost .net .EasyPostResource ;
55
6- import java .util .Arrays ;
76import java .util .HashMap ;
8- import java .util .HashSet ;
97import java .util .List ;
108import java .util .Map ;
119
@@ -1035,8 +1033,22 @@ public Shipment insure(final String apiKey) throws EasyPostException {
10351033 * @param deliveryAccuracy Delivery days accuracy restriction to use when filtering.
10361034 * @return lowest Smartrate object
10371035 * @throws EasyPostException when the request fails.
1036+ * @deprecated use {@link #lowestSmartRate(int, SmartrateAccuracy)} instead.
10381037 */
1038+ @ Deprecated
10391039 public Smartrate lowestSmartRate (int deliveryDay , String deliveryAccuracy ) throws EasyPostException {
1040+ return this .lowestSmartRate (deliveryDay , SmartrateAccuracy .getByKeyName (deliveryAccuracy ));
1041+ }
1042+
1043+ /**
1044+ * Get the lowest smartrate for this Shipment.
1045+ *
1046+ * @param deliveryDay Delivery days restriction to use when filtering.
1047+ * @param deliveryAccuracy Delivery days accuracy restriction to use when filtering.
1048+ * @return lowest Smartrate object
1049+ * @throws EasyPostException when the request fails.
1050+ */
1051+ public Smartrate lowestSmartRate (int deliveryDay , SmartrateAccuracy deliveryAccuracy ) throws EasyPostException {
10401052 List <Smartrate > smartrates = this .getSmartrates ();
10411053
10421054 Smartrate lowestSmartrate = findLowestSmartrate (smartrates , deliveryDay , deliveryAccuracy );
@@ -1074,12 +1086,12 @@ public List<Smartrate> smartrates() throws EasyPostException {
10741086 * @param deliveryAccuracy Delivery days accuracy restriction to use when filtering.
10751087 * @return lowest Smartrate object
10761088 * @throws EasyPostException when the request fails.
1077- * @deprecated Use {@link #findLowestSmartrate(List, int, String )} instead.
1089+ * @deprecated Use {@link #findLowestSmartrate(List, int, SmartrateAccuracy )} instead.
10781090 */
10791091 @ Deprecated
10801092 public static Smartrate getLowestSmartRate (final List <Smartrate > smartrates , int deliveryDay ,
10811093 String deliveryAccuracy ) throws EasyPostException {
1082- return findLowestSmartrate (smartrates , deliveryDay , deliveryAccuracy );
1094+ return findLowestSmartrate (smartrates , deliveryDay , SmartrateAccuracy . getByKeyName ( deliveryAccuracy ) );
10831095 }
10841096
10851097 /**
@@ -1092,19 +1104,11 @@ public static Smartrate getLowestSmartRate(final List<Smartrate> smartrates, int
10921104 * @throws EasyPostException when the request fails.
10931105 */
10941106 public static Smartrate findLowestSmartrate (final List <Smartrate > smartrates , int deliveryDay ,
1095- String deliveryAccuracy ) throws EasyPostException {
1107+ SmartrateAccuracy deliveryAccuracy ) throws EasyPostException {
10961108 Smartrate lowestSmartrate = null ;
10971109
1098- HashSet <String > validDeliveryAccuracies = new HashSet <String >(
1099- Arrays .asList ("percentile_50" , "percentile_75" , "percentile_85" , "percentile_90" , "percentile_95" ,
1100- "percentile_97" , "percentile_99" ));
1101-
1102- if (!validDeliveryAccuracies .contains (deliveryAccuracy .toLowerCase ())) {
1103- throw new EasyPostException ("Invalid delivery_accuracy value, must be one of: " + validDeliveryAccuracies );
1104- }
1105-
11061110 for (Smartrate rate : smartrates ) {
1107- int smartrateDeliveryDay = rate .getTimeInTransit ().getSmartRateAccuracy (deliveryAccuracy );
1111+ int smartrateDeliveryDay = rate .getTimeInTransit ().getBySmartrateAccuracy (deliveryAccuracy );
11081112
11091113 if (smartrateDeliveryDay > deliveryDay ) {
11101114 continue ;
0 commit comments