public List<ShopOrder> getCompoundOrders(
      ShopOrder localOrder, int localQty, List<ShopOrder> partialOrders) {

    System.out.println("getCompoundOrders");

    List<Marketplace> marketplaces = wirc.getAll("localhost:8180", "Marketplace");

    System.out.println("getCompoundOrders:marketlaces" + marketplaces);

    int itemsToOrder = localOrder.getQty() - localQty;

    for (Marketplace mp : marketplaces) {

      if (localOrder.getMarketIdTgt().equals((mp.getId().toString()))) continue;

      Stock foreigenStock =
          (Stock) wirc.getByPath(mp.getURL(), "Stock", "prdid", localOrder.getProductID());

      // ---------------------------------------
      if (foreigenStock == null) continue;
      // ---------------------------------------

      int items4ThisOrder =
          (itemsToOrder > foreigenStock.getQty()) ? foreigenStock.getQty() : itemsToOrder;

      if (items4ThisOrder > 0) {

        ShopOrder po = new ShopOrder();

        po.setMarketIdSrc(localOrder.getMarketIdSrc());
        po.setMarketIdTgt(mp.getId().toString());
        po.setProductID(localOrder.getProductID());
        po.setQty(items4ThisOrder);
        po.setUser(localOrder.getUser());
        po.setUserEmail(localOrder.getUserEmail());
        po.setBusinessKey(localOrder.getBusinessKey());

        partialOrders.add(po);

        itemsToOrder -= po.getQty();

        System.out.println("partialOrder:" + po);
      }
    }

    if (itemsToOrder > 0) {
      System.out.println("getCompoundOrders:Not enough items:" + itemsToOrder);
      return null;
    }

    priceOrders(partialOrders);

    return partialOrders;
  }
  public static List<ShopOrder> assembleOffer(ShopOrder lo) {

    System.out.println("assembleOffer:" + lo);

    OrderService os = new OrderService();

    Stock ls = (Stock) wirc.getByPath("localhost:8180", "Stock", "prdid", lo.getProductID());
    Product lp = (Product) wirc.getByID("localhost:8180", "Product", new Long(lo.getProductID()));

    List<ShopOrder> folist = new ArrayList<ShopOrder>();

    System.out.println("assembleOffer:folist:" + folist);

    int itemsLocal = 0;

    if (ls != null && ls.getQty() > 0) {

      itemsLocal = (lo.getQty() > ls.getQty()) ? ls.getQty() : lo.getQty();

      ShopOrder nol = new ShopOrder();

      nol.setProductID(lo.getProductID());
      nol.setMarketIdSrc(lo.getMarketIdSrc());
      nol.setMarketIdTgt(lo.getMarketIdSrc()); // eq.
      nol.setQty(itemsLocal);
      nol.setPrice(lp.getPrice() * itemsLocal);
      nol.setFrgPrice((long) 0);
      nol.setRate(1);
      nol.setUser(lo.getUser());
      nol.setUserEmail(lo.getUserEmail());
      nol.setBusinessKey(lo.getBusinessKey());

      System.out.println("LocalpartialOrder:" + nol);

      folist.add(nol);

      System.out.println("assembleOffer:folist:nol:" + folist);
    }

    System.out.println("assembleOffer:folist:getCompoundOrders:" + folist);
    folist = os.getCompoundOrders(lo, itemsLocal, folist);

    System.out.println("assembleOffer:folist:getCompoundOrders:" + folist);

    return folist;
  }