同步循环中的异步ajax

Expected Result:

I want the variable d is the minimum date. (02/03)

Actual Result

But after I run the code my alert returns the current date (23/03)..
If I add an alert when my variable is modify I have :
- "done : 2016-03-23"
- "2016-03-02" (the variable is modify after the final alert)

I understand the problem but I don't know how to solve it.

I'm not much familiar with Ajax. Please can anyone help me?
Let me know if you need more explanation.

Thanks.

Here is my code :

var d = moment(Date.now()).format('YYYY-MM-DD hh:mm:ss');       

$.when.apply($, $.map(Object.keys(filtres), function(f) {
    var query = $.ajax({
        type: "POST",
        url: "DB.php",
        data : {
            func: "getDateNextMilestone",
            typeMilestione: f,
            lab: lab,
        labelCurrent: filtres[f] 
        },
        dataType: "json"
    });
    query.done(function(data){
        data.forEach(function(a,i){
            if (a.borneSup != null){
                if(moment(a.borneSup)<moment(d)){
                    d = moment(a.borneSup).format('YYYY-MM-DD hh:mm:ss');
                }
            }
        });
    }).fail(function (a, b) {
        console.log(b)
    });     
})).done(function() {
    alert("done :"+d);
});

call your synchrous loop in "done" section like this:

...
})).done(function() {
    //alert("done :"+d);
    *loop or function with final value (in this case d) *
});