Skip to main content
Published: September 23 2005, 2:46:00 PMUpdated: July 26 2022, 2:55:49 AM

The GetItemCall returns basic shipping information. Based on the response of the GetItemCall, you can determine if the shipping type is calculated or flat. If the shipping type is calculated, you need to make a call to GetItemShipping, specifying the destination postal code and country, in order to retrieve shipping cost information for the buyer's location.

Please note that item.getShippingDetails().getShippingType() does not return a value, since this information can be derived, based on whether the ItemType.ShippingDetails.CalculatedShippingRate property is set or is null. The sample code below shows the logic to check this value.

Below is a code snippet using the Java SDK that retrieves shipping information from GetItem, determines if Calculate or Flat rate shipping is specified, and then calls GetItemShipping in the case where Calculated Shipping has been specified.

// GetItem Call
GetItemCall api = new GetItemCall(apiContext);
DetailLevelCodeType[] detailLevel = new DetailLevelCodeType[] {
DetailLevelCodeType.ReturnAll,
};
api.setDetailLevel(detailLevel);

ItemIDType CalcRateID = new ItemIDType("4576664843"); //Example Calculated Shipping Rate Item
ItemIDType FlatRateID = new ItemIDType("8323153637"); //Exampe Flat Rate Shipping Item

ItemType item = api.getItem(CalcRateID);

System.out.println("Retrieved Item Information:");

// Print the ID
System.out.println("ItemID: " + item.getItemID());

// Check for Calculated Shipping
ShippingDetailsType shipDetails = item.getShippingDetails();
CalculatedShippingRateType calcshprate = shipDetails.getCalculatedShippingRate();
if(calcshprate != null){
// This item has calculated shipping
System.out.println("The item has Calculated Rate Shipping:");

// Get Calculated Shipping Rate values
Boolean shipIrreg = calcshprate.getShippingIrregular();
ShippingPackageCodeType shppackcode = calcshprate.getShippingPackage();
MeasureType weightMaj = calcshprate.getWeightMajor();
MeasureType weightMin = calcshprate.getWeightMinor();
String origZipCode = calcshprate.getOriginatingPostalCode();
MeasureType pkgDepth = calcshprate.getPackageDepth();
MeasureType pkgWidth = calcshprate.getPackageWidth();
MeasureType pkgLength = calcshprate.getPackageLength();


// Print out Values
if(shipIrreg != null)System.out.println("\tIrregularShipping:" + shipIrreg);
if(shppackcode != null)System.out.println("\tShippingPackageCode:" + calcshprate.getShippingPackage().toString());
if(weightMaj != null)System.out.println("\tWeightMaj:" + weightMaj.getValue().toString() + " " + weightMaj.getUnit().toString());
if(weightMin != null)System.out.println("\tWeightMin:" + weightMin.getValue().toString() + " " + weightMin.getUnit().toString());
if(origZipCode != null)System.out.println("\tOriginatingPostalCode:" + origZipCode);
if(pkgDepth != null)System.out.println("\tPackageDepth:" + pkgDepth.getValue().toString() + " " + pkgDepth.getUnit().toString());
if(pkgWidth != null)System.out.println("\tPackageWidth:" + pkgWidth.getValue().toString() + " " + pkgWidth.getUnit().toString());
if(pkgLength != null)System.out.println("\tPackageLength:" + pkgLength.getValue().toString() + " " + pkgLength.getUnit().toString());

// Retrieving Shipping Cost for PostalCode 95138
GetItemShippingCall GISCall = new GetItemShippingCall(apiContext);
GISCall.setItemID(ID);
GISCall.setDestinationCountryCode(CountryCodeType.US);
GISCall.setDestinationPostalCode("48105");

System.out.println("\n\tRetrieving Costs for Destination Postal Code: "
+ GISCall.getDestinationPostalCode() + " in "
+ GISCall.getDestinationCountryCode());

// Make the call to GetItemShipping (This next line overwrites the shipDetails object returned from GetItem
shipDetails = GISCall.getItemShipping();
} else {
System.out.println("The item has Flat Rate Shipping");
}


// Regardless of Flat or Calculated Shipping, you can retrieve the ShippingServiceOptions
ShippingServiceOptionsType[] shipServOptionsAry = shipDetails.getShippingServiceOptions();

for( int i=0; i < shipServOptionsAry.length; i++){
System.out.println("\tShipping Service " + (i+1) );
if(shipServOptionsAry[i].getShippingServicePriority() != null)
System.out.println("\t\tShippingServicePriority: " + shipServOptionsAry[i].getShippingServicePriority());
if(shipServOptionsAry[i].getShippingService() != null)
System.out.println("\t\tShippingService: " + shipServOptionsAry[i].getShippingService().toString());
if(shipServOptionsAry[i].getShippingServiceCost() != null)
System.out.println("\t\tCost: " + shipServOptionsAry[i].getShippingServiceCost().getValue()
+ " " + shipServOptionsAry[i].getShippingServiceCost().getCurrencyID().toString());
if(shipServOptionsAry[i].getShippingServiceAdditionalCost() != null)
System.out.println("\t\tAdditionalCost: " + shipServOptionsAry[i].getShippingServiceAdditionalCost().getValue()
+ " " + shipServOptionsAry[i].getShippingServiceAdditionalCost().getCurrencyID().toString());
if(shipServOptionsAry[i].getShippingInsuranceCost() != null)
System.out.println("\t\tInsuranceCost: " + shipServOptionsAry[i].getShippingInsuranceCost().getValue()
+ " " + shipServOptionsAry[i].getShippingInsuranceCost().getCurrencyID().toString());
}

System.out.println("End of processing");

How well did this answer your question?
Answers others found helpful

Got thoughts? Click the feedback button – your insights help us improve!