public static void main(String[] args) throws Exception {
    VietnamAirlinesFlight vietnamFlight = new VietnamAirlinesFlight();
    CuriositySearch search = new CuriositySearch();
    search.setDepartureCode("HAN");
    search.setArrivalCode("SGN");
    search.setOutboundDate(DATE_FORMATTER.parseDateTime("2015-04-17"));
    //		search.setInboundDate(DATE_FORMATTER.parseDateTime("2013-12-30"));
    search.setAdultsCount(1);
    search.setChildrenCount(0);
    search.setInfantsCount(0);
    // search.setInboundDate(DATE_FORMATTER.parseDateTime("2015-01-10"));
    List<CuriosityFare> fares = vietnamFlight.getFare(search);
    System.err.println("Load data");
    for (CuriosityFare fare : fares) {
      System.err.println("Price " + fare.getPrice());
      System.err.println("Adult Price " + fare.getPricePerAdult());
      System.err.println("Children Price " + fare.getPricePerChild());
      System.err.println("Currency " + fare.getCurrencyCode());
      if (fare.getInboundSegments() != null) {
        for (CuriositySegment segment : fare.getOutboundSegments()) {
          System.err.println(
              segment.getAirlineCode()
                  + " "
                  + segment.getFlightNumber()
                  + " "
                  + segment.getDepartureCode()
                  + " "
                  + segment.getArrivalCode()
                  + " "
                  + segment.getDepartureTime()
                  + " - "
                  + segment.getArrivalTime());
        }
        for (CuriositySegment segment : fare.getInboundSegments()) {
          System.err.println(
              segment.getAirlineCode()
                  + " "
                  + segment.getFlightNumber()
                  + " "
                  + segment.getDepartureCode()
                  + " "
                  + segment.getArrivalCode()
                  + " "
                  + segment.getDepartureTime()
                  + " - "
                  + segment.getArrivalTime());
        }

      } else {
        for (CuriositySegment segment : fare.getOutboundSegments()) {
          System.err.println(
              segment.getAirlineCode()
                  + " "
                  + segment.getFlightNumber()
                  + " "
                  + segment.getDepartureCode()
                  + " "
                  + segment.getArrivalCode()
                  + " "
                  + segment.getDepartureTime()
                  + " - "
                  + segment.getArrivalTime());
        }
      }
    }
  }
  @Override
  public List<CuriosityFare> getFare(CuriositySearch search)
      throws IOException, InterruptedException, ExecutionException {
    try {
      List<CuriosityFare> fareDepartures = Lists.newArrayList();
      List<CuriosityFare> fareArrvials = Lists.newArrayList();
      List<CuriosityFare> fares = Lists.newArrayList();
      AirfranceFlightResponseFirst responseFirst = new AirfranceFlightResponseFirst();
      Response resultFirst = responseFirst.getResponse(search);
      Document document = Jsoup.parse(resultFirst.getResponseBody());

      FluentStringsMap requestParams = new FluentStringsMap();
      for (Element element : document.select("input[type=hidden]")) {
        requestParams.add(element.attr("name"), element.val());
      }

      search.createParam("requestParam", requestParams);

      String sId = StringUtils.substringBetween(document.toString(), "var Session='", "';");
      search.createParam("sid", "JSESSIONID=" + sId);
      AirfranceFlightResponseSecond responseSecond = new AirfranceFlightResponseSecond();

      Response resultSecond = responseSecond.getResponse(search);
      String contentSecond = resultSecond.getResponseBody();

      AirfranceFlightResponseThird responseThird = new AirfranceFlightResponseThird();
      String contentThird = responseThird.getResponse(search).getResponseBody();
      Document documentThird = Jsoup.parse(contentThird);
      String currency =
          StringUtils.substringBetween(contentThird, "tc_vars_miniRecap[\"currency\"] = \"", "\";");
      Float pricePerChild = 0F;
      Float basePriceDep = 0F;
      Float basePriceArr = 0F;
      Float basePricePerAdult = 0F;
      // System.err.print(documentThird);
      if (search.getChildrenCount() > 0) {
        String[] basePricePerAdultArr =
            documentThird.select("div#idUpsellTotalPrice").text().split(" ");

        if (basePricePerAdultArr.length == 3) {
          basePricePerAdult = Float.parseFloat(basePricePerAdultArr[0] + basePricePerAdultArr[1]);
        }
        String[] totalBaseArr =
            documentThird.select("div#idUpsellTotalPriceMultiPax").text().split(" ");
        Float totalBase = 0F;
        if (totalBaseArr.length == 3) {
          totalBase = Float.parseFloat(totalBaseArr[0] + totalBaseArr[1]);
        }
        pricePerChild =
            (totalBase - (basePricePerAdult * search.getAdultsCount())) / search.getChildrenCount();
      }
      String depContent =
          StringUtils.substringBetween(
              contentThird,
              "</script> <dl> <dt class=\"etape\"> <div class=\"titre\" id=\"idUpsellTitle0\">",
              "tc_product_css = new Array();");
      if (depContent != null && !depContent.equals("")) {
        Document depDocument = Jsoup.parse(depContent);
        Elements depElements = depDocument.select("table.upsellRow");
        for (Element element : depElements) {
          Elements segmentElements = element.select("tbody>tr");
          Float pricePerAdult = 0F;
          if (segmentElements.size() > 0) {
            pricePerAdult =
                Float.parseFloat(segmentElements.get(0).select("input[name=price]").val());
          }
          Float priceTotal =
              Float.parseFloat(segmentElements.get(0).select("input[name=priceMultiPax]").val());
          List<CuriositySegment> outboundSegments = parseSegments(element);
          CuriosityFare fare = new CuriosityFare();

          // fare.setTotalPrice(pricePerAdult*search.getAdultsCount(),search);
          fare.setOutboundSegments(outboundSegments);
          fare.setCurrencyCode(currency);
          fare.setAirlineCode("AF");
          fare.setPrice(priceTotal);
          fare.setPricePerAdult(priceTotal / search.getPassengersCount());
          if (search.getChildrenCount() > 0) {
            fare.setPricePerChild(priceTotal / search.getPassengersCount());
          }
          fareDepartures.add(fare);
        }

        if (search.isRoundtrip()) {
          // System.err.print(contentThird);
          int i = 0;
          for (CuriosityFare depFare : fareDepartures) {
            search.getParams().clear();
            search.createParam("sid", "JSESSIONID=" + sId);
            search.createParam("selected", i);
            AirfranceFlightResponseFour responseFour = new AirfranceFlightResponseFour();
            String contentFour = responseFour.getResponse(search).getResponseBody();
            // System.err.print(contentFour);
            //					AirfranceFlightResponseThird newResponseThird = new
            // AirfranceFlightResponseThird();
            //					String newContentThird = newResponseThird.getResponse(search).getResponseBody();
            //	System.err.print(newContentThird);
            String arrContent =
                StringUtils.substringBetween(
                    contentThird,
                    "</script> <dl> <dt class=\"etape\"> <div class=\"titre\" id=\"idUpsellTitle1\">",
                    "tc_product_css = new Array();");
            Document arrpDocument = Jsoup.parse(contentFour);
            Elements arrElements = arrpDocument.select("table.upsellRow");
            // System.err.print(arrElements);
            for (Element element : arrElements) {
              String isCheap =
                  element
                      .select("tbody>tr")
                      .get(0)
                      .select("td.upsellRadio>span.upsellFareCheap")
                      .text();
              if (isCheap != null && !isCheap.equalsIgnoreCase("")) {
                Elements segmentElements = element.select("tbody>tr");
                Float pricePerAdult = 0F;
                if (segmentElements.size() > 0) {
                  pricePerAdult =
                      Float.parseFloat(segmentElements.get(0).select("input[name=price]").val());
                }
                List<CuriositySegment> inboundSegments = parseSegments(element);
                CuriosityFare fare = new CuriosityFare();
                fare.setOutboundSegments(depFare.getOutboundSegments());
                fare.setInboundSegments(inboundSegments);
                Float basePricePerAdultRT = depFare.getPricePerAdult();
                fare.setPricePerAdult(depFare.getPrice() / search.getPassengersCount());
                if (search.getChildrenCount() > 0) {
                  fare.setPricePerChild(depFare.getPrice() / search.getPassengersCount());
                }
                fare.setPrice(depFare.getPrice());
                fare.setCurrencyCode(currency);
                fare.setAirlineCode("AF");
                fares.add(fare);
              }
            }
            i++;
          }

        } else {
          //				if (search.getChildrenCount()>0) {
          //					for (CuriosityFare fareDep : fareDepartures) {
          //						Float basePricePerAdultOW = fareDep.getBasePricePerAdult();
          //						Float price = fareDep.getPrice();
          //						price +=
          // ((basePricePerAdultOW/basePricePerAdult)*pricePerChild)*search.getChildrenCount();
          //						fareDep.setPrice(price);
          //						fares.add(fareDep);
          //					}
          //				}else{
          fares.addAll(fareDepartures);
          //				}
        }
      }
      return fares;
    } catch (Exception e) {
      return null;
    }
  }