com.easypost.app.BatchExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easypost-api-client Show documentation
Show all versions of easypost-api-client Show documentation
EasyPost Java Client Library for the EasyPost Shipping API
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.lang.InterruptedException;
import com.easypost.EasyPost;
import com.easypost.exception.EasyPostException;
import com.easypost.model.Address;
import com.easypost.model.Parcel;
import com.easypost.model.CustomsItem;
import com.easypost.model.CustomsInfo;
import com.easypost.model.Shipment;
import com.easypost.model.Batch;
public class BatchExample {
public static void main(String[] args) throws InterruptedException {
EasyPost.apiKey = "cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi";
try {
Map fromAddressMap = new HashMap();
fromAddressMap.put("name", "Simpler Postage Inc");
fromAddressMap.put("street1", "388 Townsend St");
fromAddressMap.put("street2", "Apt 20");
fromAddressMap.put("city", "San Francisco");
fromAddressMap.put("state", "CA");
fromAddressMap.put("zip", "94107");
fromAddressMap.put("phone", "415-456-7890");
Address fromAddress = Address.create(fromAddressMap);
Map parcelMap = new HashMap();
parcelMap.put("weight", 22.9);
parcelMap.put("height", 12.1);
parcelMap.put("width", 8);
parcelMap.put("length", 19.8);
Parcel parcel = Parcel.create(parcelMap);
// Customs info - this is required for international destinations
Map customsItem1Map = new HashMap();
customsItem1Map.put("description", "EasyPost T-shirts");
customsItem1Map.put("quantity", 2);
customsItem1Map.put("value", 23.56);
customsItem1Map.put("weight", 18.8);
customsItem1Map.put("origin_country", "us");
customsItem1Map.put("hs_tariff_number", "610910");
Map customsItem2Map = new HashMap();
customsItem2Map.put("description", "EasyPost Stickers");
customsItem2Map.put("quantity", 11);
customsItem2Map.put("value", 8.98);
customsItem2Map.put("weight", 3.2);
customsItem2Map.put("origin_country", "us");
customsItem2Map.put("hs_tariff_number", "654321");
Map customsInfoMap = new HashMap();
customsInfoMap.put("customs_certify", true);
customsInfoMap.put("customs_signer", "Dr. Pepper");
customsInfoMap.put("contents_type", "gift");
customsInfoMap.put("eel_pfc", "NOEEI 30.37(a)");
customsInfoMap.put("non_delivery_option", "return");
customsInfoMap.put("restriction_type", "none");
CustomsItem customsItem1 = CustomsItem.create(customsItem1Map);
CustomsItem customsItem2 = CustomsItem.create(customsItem2Map);
List customsItemsList = new ArrayList();
customsItemsList.add(customsItem1);
customsItemsList.add(customsItem2);
customsInfoMap.put("customs_items", customsItemsList);
CustomsInfo customsInfo = CustomsInfo.create(customsInfoMap);
// this will be coming from your database or other input source
// hard coding it here for demonstration purposes only
List