Differential equations in metric spaces with applications