}
// get the ShipmentCostEstimate(s)
Map<String, String> estFields = UtilMisc.toMap("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId,
"carrierPartyId", carrierPartyId, "carrierRoleTypeId", carrierRoleTypeId);
EntityCondition estFieldsCond = EntityCondition.makeCondition(estFields, EntityOperator.AND);
if (UtilValidate.isNotEmpty(productStoreShipMethId)) {
// if the productStoreShipMethId field is passed, then also get estimates that have the field set
List<EntityCondition> condList = UtilMisc.toList(EntityCondition.makeCondition("productStoreShipMethId", EntityOperator.EQUALS, productStoreShipMethId), estFieldsCond);
estFieldsCond = EntityCondition.makeCondition(condList, EntityOperator.AND);
}
Collection<GenericValue> estimates = null;
try {
estimates = delegator.findList("ShipmentCostEstimate", estFieldsCond, null, null, null, true);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"ProductShipmentCostEstimateCannotRetrieve", locale));
}
if (estimates == null || estimates.size() < 1) {
if (initialEstimateAmt.compareTo(BigDecimal.ZERO) == 0) {
Debug.logWarning("No shipping estimates found; the shipping amount returned is 0! Condition used was: " + estFieldsCond + "; Using the passed context: " + context, module);
}
Map<String, Object> respNow = ServiceUtil.returnSuccess();
respNow.put("shippingEstimateAmount", BigDecimal.ZERO);
return respNow;
}
// Get the PostalAddress
GenericValue shipAddress = null;
if (shippingContactMechId != null) {
try {
shipAddress = delegator.findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", shippingContactMechId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"ProductShipmentCostEstimateCannotGetShippingAddress", locale));
}
} else if (shippingPostalCode != null) {
String countryGeoId = null;
try {
EntityCondition cond =EntityCondition.makeCondition(UtilMisc.toMap("geoTypeId", "COUNTRY", "geoCode", shippingCountryCode));
GenericValue countryGeo = EntityUtil.getFirst(delegator.findList("Geo", cond, null, null, null, true));
if (countryGeo != null) {
countryGeoId = countryGeo.getString("geoId");
}
} catch (GenericEntityException e) {